import request from '@/utils/request'
import type { Response, DivisionData } from '@/utils/type'
import type {
  addDeptParams,
  deptQueryParams,
} from '@/api/back-management/dept/interface'
import { AxiosResponse } from 'axios'

/**
 * 获取部门列表
 *
 * @param {deptQueryParams} params 查询参数
 */
export const queryDeptList = (
  params: deptQueryParams | null
): Promise<Response<DivisionData[]>> => {
  // /resource/area/query
  return request('/resource/area/queryDepartTree', {
    method: 'GET',
    params,
  })
}

/**
 * 获取部门列表
 *
 * @param {deptQueryParams} params 查询参数
 */
export const queryDeptListOld = (
  params: deptQueryParams | null
): Promise<Response<Array<DivisionData> | null>> => {
  return request('/resource/area/query', {
    method: 'GET',
    params,
  })
}

/**
 * 部门列表新增
 *
 * @param {addDeptParams} params 查询参数
 */
export const addDept = (params: addDeptParams) => {
  return request('/resource/area/add', {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 部门列表更新
 */
export const updateDept = (areaCode: string, params: addDeptParams) => {
  return request(`/resource/area/update/${areaCode}`, {
    method: 'PUT',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 部门列表更新
 */
export const updateDeptNew = (params: addDeptParams) => {
  return request(`/resource/area/updateInfo`, {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 部门列表删除
 */
export const deleteDept = (areaCode: string) => {
  return request(`/resource/area/delete?areacodes=${areaCode}`, {
    method: 'DELETE',
  }) as Promise<Response<any>>
}

/**
 * 部门导出
 */
export const deptExport = (params: any) => {
  return request(`/resource/area/export`, {
    method: 'GET',
    responseType: 'blob',
    params,
  }) as Promise<AxiosResponse<Blob>>
}
